require(['./config'], function() {
  require(['jquery', 'util', 'swiper', 'easydropdown','Cookies','text!/common/nav.html','text!/common/footer.html','navInit','lazyload'], function(
    $,
    util,
    Swiper,
    easydropdown,
    Cookies,
    navHtml,
    footerHtml,
    navInit
  ) {
    $(".global-nav").html(navHtml);
    $(".global-footer").html(footerHtml);
    navInit();

    function renderNews(arr){
      for (var i=0;i<arr.length;i++)
      {
        var item=arr[i];
        $(".news"+i+"-imglink").attr("href",'/news/newsdetail.html?id='+item.id);
        $(".news"+i+"-img").attr("src",item.image);
        $(".news"+i+"-link").attr("href",'/news/newsdetail.html?id='+item.id);
        $(".news"+i+"-link").text(item.title);
        $(".news"+i+"-summary").text(item.summary);
        $(".news"+i+"-time").text(item.createTime);
      }
    }

    $(function() {
      // Swiper轮播js代码
      var swiper = new Swiper('.swiper-container', {
        pagination: '.swiper-pagination',
        nextButton: '.swiper-button-next',
        prevButton: '.swiper-button-prev',
        paginationClickable: true,
        spaceBetween: 30,
        centeredSlides: true,
        autoplay: 2500,
        autoplayDisableOnInteraction: false,
        lazyLoading : true
      })

      $("img.lazyload").lazyload();

      //品牌翻转
      var turn = function(target, time, opts) {
        target.find('.tool-wrap').hover(
          function() {
            $(this)
              .find('img')
              .animate(opts[0], time, function() {
                $(this)
                  .hide()
                  .next()
                  .show()
                $(this)
                  .next()
                  .animate(opts[1], time)
              })
          },
          function() {
            $(this)
              .find('.mask-img')
              .animate(opts[0], time, function() {
                $(this)
                  .hide()
                  .prev()
                  .show()
                $(this)
                  .prev()
                  .animate(opts[1], time)
              })
          }
        )
      }
      var verticalOpts = [{ width: 0 }, { width: '200px' }]
      turn($('#tool'), 200, verticalOpts)

       $.ajax({
        url: util.host+'/news/list?recommend=1&limit=2&hot=0',
        type:"GET",
        success:function(res){
          renderNews(res.data.rows);
        }
       })
    })

    
    
  })
})
